#include <stdio.h>
#include <string.h>
#include "haffman_main.h"

void print_use()
{
	printf("Use:\n\thaffman_nasm_console -c SOURCE DESTINATION\t-\tto compress\n\t\t\tor\n\thaffman_nasm_console -d SOURCE DESTINATION\t-\tto decompress\n\t\t\tor\n\thaffman_nasm_console -h\t-\tfor help\n\nMaxim Akinin\n2008 - 2009\n");
};

int main(const int argv,const char *argc[])
{
	unsigned char ret;
	if(argv == 2 && !strcmp(argc[1],"-h"))
	{
		print_use();
		return 0;
	}
	if(argv < 4)
	{
		printf("TOO MANY ARGUMENTS\n");
		print_use();
		return 1;
	}
	if(argv > 4)
	{
		printf("TOO MUCH ARGUMENTS\n");
		print_use();
		return 1;
	}
	if(strcmp(argc[1],"-c") && strcmp(argc[1],"-d"))
	{
		printf("BAD ARGUMENTS\n");
		print_use();
		return 1;
	}

	if(!strcmp(argc[1],"-c"))
		ret = haffman_compress(argc[2],argc[3]);
	else
		ret = haffman_decompress(argc[2],argc[3]);

	if(ret != 0)
	{
		printf("[%u] %s\n",ret,get_error_description(ret));
		return 1;
	};
	return 0;
}

